//
//  HomePageSectionHeader.m
//  ZhiHuDaily
//
//  Created by 吴宜昊 on 2022/2/6.
//

#import "HomePageSectionHeader.h"

@interface HomePageSectionHeader ()
@property(nonatomic,strong) UILabel * labelDate;
@property(nonatomic,strong) UIView * lineView;
@property(nonatomic,strong) UIView * bgView;
@end
@implementation HomePageSectionHeader

#pragma mark - override
-(instancetype) initWithReuseIdentifier:(NSString *) reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void) updateConstraints {
    [self remakeMas];
    [super updateConstraints];
}

#pragma mark - remakeMas
-(void) remakeMas {
    WeakSelf(self);
    [self.labelDate mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@16);
        make.centerY.equalTo(@0);
    }];

    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        StrongSelf(weakSelf);
        make.left.equalTo( strongSelf.labelDate.mas_right ).offset(16);
        make.right.equalTo(@-16);
        make.centerY.equalTo(@0);
        make.height.equalTo(@0.5);
    }];
}

#pragma mark - override
-(void) setupUI {
    [self.contentView addSubview:self.labelDate];
    [self.contentView addSubview:self.lineView];
    [self setNeedsUpdateConstraints];
    self.backgroundView = self.bgView;
}

#pragma mark - lazy
-(void)setFrame:(CGRect)frame {
    if (frame.size.width == 0) {
        frame = CGRectMake(0, 0, kScreenWidth, 60);
    }
    [super setFrame:frame];
}

-(UILabel *) labelDate {
    if (!_labelDate) {
        _labelDate = [UILabel new];
        _labelDate.font = FontPingFangRegular(13);
        _labelDate.textColor = HEXCOLOR(0xA8A8A8);
        _labelDate.text = @"00月00日";
    }
    return _labelDate;
}

-(UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = HEXCOLOR(0xB8B8B8);
    }
    return _lineView;
}

-(UIView *) bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = UIColor.whiteColor;
    }
    return _bgView;
}

#pragma mark - OPEN API
-(void) updateDate:(NSString *) strDate {
    DateModel * model = [DateModel modelWithString:strDate];
    _labelDate.text = [NSString stringWithFormat:@"%02ld月%02ld日",model.month,model.day];
}
@end
